package com.lvmama.monkey.common.utils.JDBCUtils

import java.util.Properties

import com.lvmama.monkey.config.ConfigHelper

import scala.collection.mutable

/**
  * Created by hejing on 2017/10/11.
  */
object JDBCTemplate {
  private val properties = ConfigHelper.getProperties("db-config.properties")
  private def getJDBCConn = properties.getProperty("jdbc.conn")

  def getConProperties: Properties = {
    val p = new Properties()
    p.setProperty("maxActive", properties.getProperty("jdbc.maxActive"))
    p.setProperty("maxWait", properties.getProperty("jdbc.maxWait"))
    p.setProperty("maxIdle", properties.getProperty("jdbc.maxIdle"))
    p.setProperty("initSize", properties.getProperty("jdbc.initSize"))
    p.setProperty("removeAbandoned", "true")
    p.setProperty("testWhileIdle", "true")
    p.setProperty("testOnBorrow", "true")
    p.setProperty("validationQuery", "select 1")
    p.setProperty("driver",properties.getProperty("jdbc.driverClassName"))
    p
  }

  private def getDriver ={
    properties.getProperty("jdbc.driverClassName")
  }

  val JDBCDefaultSet: Map[String, String] = {
    val m = mutable.Map.empty[String, String]
    m += ("conn" -> getJDBCConn)
    m += ("driver" -> getDriver)
    m += ("url" -> properties.getProperty("jdbc.url"))
    m += ("user" -> properties.getProperty("jdbc.username"))
    m += ("password" -> properties.getProperty("jdbc.password"))
    m.toMap
  }

  def main(args: Array[String]): Unit = {
    ConfigHelper.getProperties("db-config.properties")
  }
}